package com.peng;

public class TankWallCollider implements Collider {
    @Override
    public boolean collide(GameObject g1, GameObject g2) {
        Tank tank;
        Wall wall;
        if (g1 instanceof Wall && g2 instanceof Tank) {
            tank = (Tank) g2;
            wall = (Wall) g1;

        } else if (g1 instanceof Tank && g2 instanceof Wall) {
            tank = (Tank) g1;
            wall = (Wall) g2;
        } else {
            return false;
        }
        if (tank.getRectangle().intersects(wall.getRectangle())) {
            if (tank.getGroup() == Group.GOOD) return false;
            tank.reverseDir();
        }

        return false;
    }


}
